package com.pair.micro.fee.modules.charge.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pair.micro.common.mybatis.service.impl.BaseServiceImpl;
import com.pair.micro.fee.modules.charge.convert.GardenGridConvert;
import com.pair.micro.fee.modules.charge.dao.GardenGridDao;
import com.pair.micro.fee.modules.charge.entity.GardenGridEntity;
import com.pair.micro.fee.modules.charge.query.GardenGridQuery;
import com.pair.micro.fee.modules.charge.service.GardenGridService;
import com.pair.micro.fee.modules.charge.vo.GardenGridVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class GardenGridServiceImpl extends BaseServiceImpl<GardenGridDao, GardenGridEntity> implements GardenGridService {
    @Override
    public List<GardenGridVO> selectGardenGridList(GardenGridQuery query) {

        List<GardenGridEntity> entityList =  baseMapper.selectList(getWrapper(query));
        return GardenGridConvert.INSTANCE.convertList(entityList);
    }

    private Wrapper<GardenGridEntity> getWrapper(GardenGridQuery query){
        LambdaQueryWrapper<GardenGridEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(query.getType() != null, GardenGridEntity::getType, query.getType());
        wrapper.eq(query.getParentId() != null, GardenGridEntity::getParentId, query.getParentId());
        wrapper.orderByAsc(GardenGridEntity::getName);

        return wrapper;
    }
}
